package cn.hjm.org.service.impl;

import cn.hjm.basic.util.PageList;
import cn.hjm.org.domain.Department;
import cn.hjm.org.mapper.DepartmentMapper;
import cn.hjm.org.query.DepartmentQuery;
import cn.hjm.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    @Transactional
    public void add(Department department) {
        departmentMapper.save(department);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);

    }

    @Override
    @Transactional
    public void remove(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    public Department findById(Long id) {
        return departmentMapper.loadById(id);
    }

    @Override
    public List<Department> findAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public PageList<Department> Querypage(DepartmentQuery departmentQuery) {
        PageList p=new PageList();
        Long count = departmentMapper.queryCount(departmentQuery);
        List<Department> list = departmentMapper.loadByQuery(departmentQuery);
        p.setRows(list);
        p.setTotals(count);
        return p;
    }
}
